package com.kanas.webak.config.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;

import com.kanas.framework.support.AbstractModel;
import com.kanas.framework.util.StringUtils;

@Entity
@Table(name="kanas_data_dict_value")
@JsonIgnoreProperties({"parent","childrens","dictType"})
public class DictValue extends AbstractModel {

	@Transient
	private static final long serialVersionUID = 1L;

	@Id
	@Column(name="id", length=32)
	private String id;
	@Column(name="code", length=100)
	private String code;
	@Column(name="label", length=100)
	private String label;
	@Column(name="sort_number")
	private Integer sortNumber;
	@Column(name="active_flag")
	private Boolean activeFlag;
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="parent_id",referencedColumnName="id")
	private DictValue parent;
	@OneToMany(mappedBy = "parent", cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH}, fetch = FetchType.LAZY)
	private Set<DictValue> childrens;
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="type_id",referencedColumnName="id")
	private DictType dictType;
	
	
	@Transient
	private String oldId;
	@Transient
	private String parentId;
	
	public DictValue() {
		this.id = StringUtils.generateUUID();
	}
	
	public DictValue(String code, String label, String typeCode, Boolean activeFlag) {
		this.id = StringUtils.generateUUID();
		this.label = label;
		this.activeFlag = activeFlag;
	}
	
	@Override
	public String toIdString() {
		return id;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public DictValue getParent() {
		return parent;
	}

	public void setParent(DictValue parent) {
		this.parent = parent;
	}

	public Set<DictValue> getChildrens() {
		if(childrens==null)childrens = new HashSet<DictValue>();
		return childrens;
	}

	public void setChildrens(Set<DictValue> childrens) {
		this.childrens = childrens;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Integer getSortNumber() {
		return sortNumber;
	}

	public void setSortNumber(Integer sortNumber) {
		this.sortNumber = sortNumber;
	}

	public Boolean getActiveFlag() {
		return activeFlag;
	}

	public void setActiveFlag(Boolean activeFlag) {
		this.activeFlag = activeFlag;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public String getOldId() {
		return oldId;
	}

	public void setOldId(String oldId) {
		this.oldId = oldId;
	}

	public DictType getDictType() {
		return dictType;
	}

	public void setDictType(DictType dictType) {
		this.dictType = dictType;
	}
	
}
